home *** CD-ROM | disk | FTP | other *** search
/ Ahoy 1987 April / Ahoy_Magazine_87-04_1987_Double_L.d64 / Fancy Factorials (.txt) < prev    next >
Commodore BASIC  |  2022-10-26  |  1KB  |  33 lines

  1. 0 print"[147]":poke53280,0:poke53281,0:poke646,1
  2. 1 rem ==================================
  3. 2 rem    commodares problem #36-1 :
  4. 3 rem    fancy factorials
  5. 4 rem
  6. 90 rem----solution by matt shapiro------
  7. 100 h=100000:e=.0000001:i=0:j=0:k=1:c=0:p=0:n=0:dimf(3000):f(1)=1:input"n";n
  8. 110 for i=1 to n:for j=1 to k:p=i*f(j)+c:c=int(p/h+e):f(j)=p-h*c:next
  9. 120 if c then k=k+1 : f(k)=c : c=0
  10. 130 next:print mid$(str$(n),2)"!="mid$(str$(f(k)),2);
  11. 140 ifk>1thenforj=k-1to1step-1:printright$("0000"+mid$(str$(f(j)),2),5);:next
  12. 150 end
  13. 190 rem----solution by rob schultz------
  14. 200 input "n";n : m=1
  15. 210 for j=1 to n : m=m*j
  16. 220 if m>=10 then m=m/10 :e=e+1:goto 220
  17. 230 next : print m "e+" e
  18. 240 end
  19. 290 rem---solution by charles kluepfel--
  20. 300 input "n";n : print n"[157]! = ";
  21. 310 ln=log(n)*(n+.5)-n+log(2*(NULL))/2+1/(12*n)-1/(360*n*n*n)
  22. 320 ln=ln+1/(1260*n*n*n*n*n)-1/(1680*n*n*n*n*n*n*n)
  23. 330 if n<12 then print int(exp(ln)+.5) : goto 360
  24. 340 lg=ln/log(10) : ch=int(lg) :mn=lg-ch
  25. 350 print left$(str$(exp(mn*log(10)))+"0000000000",12-len(str$(ch)));"e"mid$(str$(ch),2)
  26. 360 end
  27. 390 rem------stirling's formula---------
  28. 400 input "specify n less than 34";n
  29. 410 nf=sqr(2*(NULL)*n)*(n/exp(1))^n
  30. 420 print n "! >" nf
  31. 430 print n "! <" nf*(1+1/(12*n-1))
  32. 440 end
  33.